package yto.freemarker.java8.dateapi;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 解决传统的时间在多线程下的安全性的问题
 *
 * @author dongxing
 * @create 2018-06-23 17:55
 **/
public class DateFormatThreadLocal {

    private static final ThreadLocal<DateFormat> THREAD_LOCAL = new ThreadLocal<DateFormat>(){
        @Override
        protected DateFormat initialValue() {
            return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        }
    };


    public static Date convert(String cource) throws ParseException {
        return THREAD_LOCAL.get().parse(cource);
    }
}
